<script>
	// import xcxCheckUpdate from '@/common/xcxCheckUpdate.js'

	export default {

		//全局变量
		globalData: {
			//用于判断用户是否登录(默认为否)
			userLogin: false,
		},
		onLaunch: function() {
			console.log('App Launch')
			//是否判断登录
			wx.checkSession({
				success: () => {
					//没用到token可以直接忽略以下步骤:
					console.log('登录未过期');
					const user_token = uni.getStorageSync('token');
					const userinfo = uni.getStorageSync('userinfo');
					if (user_token) {
						if (userinfo.isMember==1) {
							this.globalData.userLogin = true;
						} else {
							uni.showToast({
								title: "请先开通会员",
								duration: 2000,
								icon:"error"

							})
							
						}

					} else {
						//解决token消失但登录未过期问题
						this.globalData.userLogin = false;
						//没登录就异步删除验证token
						uni.removeStorage({
							key: 'token',
							success: function(res) {
								console.log('token移除成功');
							}
						});
						uni.showToast({
							title: "请开通会员",
							duration: 2000,
							icon:"error"
						
						})
						
					}
					//没用到token走这个步骤:
					//this.globalData.userLogin = false;
				},
				fail: () => {
					console.log('登录已过期');
					this.globalData.userLogin = false;
					//没用到token可以直接忽略以下步骤:
					//没登录就异步删除验证token
					uni.removeStorage({
						key: 'token',
						success: function(res) {
							console.log('token移除成功');
						}
					});
					uni.showToast({
						title: "请登录",
						duration: 2000,
						icon:"error"
					
					})
					uni.switchTab({
						url:'/pages/user/user'
					})
				}
			})
		},

		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>
<!-- _UNI_146A172 -->
<style lang="scss">
	/*每个页面公共css */
	@import '@/uni_modules/uni-scss/index.scss';
	/* #ifndef APP-NVUE */
	@import '@/static/customicons.css';
	// @import "./tm-vuetify/mian.min.css";
	@import "uview-ui/index.scss";

	// 设置整个项目的背景色
	page {
		background-color: #ffffff;
	}

	* {
		box-sizing: border-box;
		margin: 0;
		padding: 0;
		list-style: none;
	}

	/* #endif */
	.example-info {
		font-size: 14px;
		color: #333;
		padding: 10px;
	}
</style>
